package com.virtualightning.mvvm.tools

import kotlinx.coroutines.CompletableDeferred

/**
 *  Anchor : Create by CimZzz
 *  Time : 2021/10/08 23:38:56
 *  Project : vl-framework
 *
 *  Activity 权限结果 Deferred
 */
class ActivityPermissionDeferred (
	val requestCode: Int,
	private val permissionList: Array<out String>
) {
	private val completeDeferred = CompletableDeferred<List<String>>()

	///////////////////////////////////////////////////////////////////////////
	// Add by CimZzz on 2021/6/7 11:40 PM
	// 等待数据返回结果
	///////////////////////////////////////////////////////////////////////////
	suspend fun await() : List<String> {
		return completeDeferred.await()
	}

	///////////////////////////////////////////////////////////////////////////
	// Add by CimZzz on 2021/6/7 11:41 PM
	// 填充数据
	///////////////////////////////////////////////////////////////////////////
	internal fun feed(data: List<String>) {
		completeDeferred.complete(data)
	}

	///////////////////////////////////////////////////////////////////////////
	// Add by CimZzz on 2021/10/12 11:43 AM
	// 取消 Deferred
	///////////////////////////////////////////////////////////////////////////
	internal fun cancel() {
		completeDeferred.complete(permissionList.toList())
	}
}